package com.tony.easymvc.core;

import java.io.File;
import java.io.IOException;

import com.google.common.io.Files;

public class FileUtils {

    public static void copy(File src, File target) throws IOException {
        if (src.isDirectory()) {
            target.mkdirs();
            File[] fs = src.listFiles();
            for (int i = 0; i < fs.length; i++) {
                File tmpFile = fs[i];
                File tmpTarget = new File(target.getPath() + "/" + tmpFile.getName());
                copy(tmpFile, tmpTarget);
            }
        } else {
            Files.copy(src, target);
        }
    }

    public static void delete(File file) {
        if (file.isDirectory()) {
            File[] temp = file.listFiles();
            for (int i = 0; i < temp.length; i++) {
                delete(temp[i]);
            }
            file.deleteOnExit();
        } else {
            file.deleteOnExit();
        }

    }

}
